<template>
  <div class="register">
    <div class="top">
      <div class="title">{{ detailStore.hospitalInfo.hospital?.hosname }}</div>
      <div class="level">
        <icon-thumb-up />
        <span>{{
          detailStore.hospitalInfo.hospital?.param.hostypeString
        }}</span>
      </div>
    </div>
    <div class="content">
      <div class="left">
        <img
          :src="`data:image/jpeg;base64,${detailStore.hospitalInfo.hospital?.logoData}`"
        />
      </div>
      <div class="right">
        <div class="rule">挂号规则:</div>
        <div class="time">
          预约周期: 10天 放号时间:
          {{ detailStore.hospitalInfo.bookingRule?.releaseTime }} 停挂时间:
          {{ detailStore.hospitalInfo.bookingRule?.stopTime }}
        </div>
        <div class="address">
          具体位置: {{ detailStore.hospitalInfo.hospital?.address }}
        </div>
        <div class="route">
          具体路线: {{ detailStore.hospitalInfo.hospital?.route }}
        </div>
        <div class="quit-time">
          退号时间: 就诊前一工作日{{
            detailStore.hospitalInfo.bookingRule?.quitTime
          }}前取消
        </div>
        <div class="rule">预约挂号规则:</div>
        <div
          class="rule-info"
          v-for="(item, index) in detailStore.hospitalInfo.bookingRule?.rule"
          :key="index"
        >
          {{ index + 1 }}. {{ item }}
        </div>
      </div>
    </div>
    <div class="department">
      <div class="leftNav">
        <ul>
          <li
            v-for="(department, index) in detailStore.hospitalDepartment"
            :key="department.depcode"
            :class="{ active: currentIndex == index }"
            @click="changeIndex(index)"
          >
            {{ department.depname }}
          </li>
        </ul>
      </div>
      <div class="department-info">
        <div
          class="show-department"
          v-for="department in detailStore.hospitalDepartment"
        >
          <h1 class="title" id="cur">
            {{ department.depname }}
          </h1>
          <ul>
            <li v-for="item in department.children" :key="item.depcode">
              {{ item.depname }}
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import useDetailStore from "@/store/modules/hospitalDetail";
import { ref } from "vue";

const detailStore = useDetailStore();

// 控制高亮的响应式数据
let currentIndex = ref<number>(0);

const changeIndex = (index: number) => {
  currentIndex.value = index;

  const allH1 = document.querySelectorAll("#cur") as NodeListOf<HTMLDivElement>;
  // scrollIntoView方法的具体使用方法请百度
  allH1[currentIndex.value].scrollIntoView({ behavior: "smooth" });
};
</script>

<style lang="scss" scoped>
.register {
  .top {
    display: flex;
    align-items: center;
    .title {
      font-size: 25px;
      font-weight: 550;
      // color: #5f5f5f;
    }
    .level {
      color: #7f7f7f;
      margin-left: 10px;
      height: 40px;
      text-align: center;
      line-height: 40px;
    }
  }
  .content {
    display: flex;
    margin-top: 20px;
    .left {
      width: 80px;
      height: 80px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .right {
      flex: 1;
      font-size: 14px;
      margin-left: 20px;

      .time,
      .address,
      .route,
      .quit-time,
      .rule-info {
        margin-top: 5px;
        color: #7f7f7f;
        line-height: 1.5;
      }
      .rule {
        margin: 12px 0;
        font-size: 18px;
      }
    }
  }

  .department {
    width: 100%;
    height: 500px;
    display: flex;
    margin-top: 20px;
    .leftNav {
      width: 80px;
      height: 100%;
      ul {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        list-style: none;
        background-color: rgb(248, 248, 248);
        li {
          flex: 1;
          text-align: center;
          color: #7f7f7f;
          font-size: 14px;
          line-height: 40px;
          cursor: pointer;
          &.active {
            border-left: 2px solid rgb(22, 93, 255);
            background-color: white;
            color: rgb(22, 93, 255);
          }
        }
      }
    }
    .department-info {
      flex: 1;
      margin-left: 20px;
      height: 100%;
      overflow: auto;
      cursor: pointer;
      &::-webkit-scrollbar {
        display: none;
      }
      .show-department {
        h1 {
          margin: 0;
          background-color: rgb(248, 248, 248);
          font-size: 14px;
          font-weight: 550;
          color: #7f7f7f;
          line-height: 30px;
        }
        ul {
          display: flex;
          flex-wrap: wrap;
          li {
            width: 33.33%;
            line-height: 30px;
            color: #7f7f7f;
            &:hover {
              color: rgb(22, 93, 255);
            }
          }
        }
      }
    }
  }
}
</style>
